<?php
/**
 * Created by PhpStorm.*
 * User: daojia
 * Date: 2020/5/8
 * Time: 11:45
 */
namespace app\api\controller;
use app\api\model\pay\Order as OrderModel;
use app\api\service\Payment as PaymentService;
use app\common\enum\OrderType as OrderTypeEnum;
class Pay extends Controller{
    public function integralJiSuan($money){
        $integral = integralJiSuan($money);
        return $this->renderSuccess([            'integral'=>$integral        ]);
    }
    /**
     * 确认支付
     * @param null $planId
     * @param int $customMoney
     * @return array
     * @throws \app\common\exception\BaseException
     * @throws \think\exception\DbException
     */
    public function submit($shopid,$customMoney = 0)    {
        // 用户信息
        $userInfo = $this->getUser();        // 生成充值订单
        $model = new OrderModel;
        if (!$model->createOrder($shopid,$userInfo, $customMoney)) {
            return $this->renderError($model->getError() ?: '支付失败');
        }
        // 构建微信支付
        $payment = PaymentService::wechat(
            $userInfo,
            $model['order_id'],
            $model['order_no'],
            $model['pay_price'],
            OrderTypeEnum::PAYHARGE
        );
        $order = ['order_id'=>$model['order_id']];
        // 充值状态提醒
        $message = ['success' => '支付成功', 'error' => '订单未支付'];
        return $this->renderSuccess(compact('order','payment', 'message'), $message);
    }
    public function orderinfo($id){
        $model = new OrderModel;
        $info = $model->getPayDetailId($id);        
        $info['shop_name'] = '随官屯宜品购--五金综合商店';
        $info['ishq'] = 0;
        $info['pages'] = '/pages/live/index';
        $info['images'] = 'https://shop.suiguantun.com/hongbao.png';
        $message = ['success' => '支付成功', 'error' => '订单未支付'];
        return $this->renderSuccess(compact('info', 'message'), $message);
    }
}